﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business;
using ZLCMS.Data.Model;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using ZLCMS.Business.DwzFrame;
using System.Reflection;
using NHibernate;
using ZLCMS.Business.Util;

namespace ZLCMS.Web.SystemManage.Basics
{
    public partial class RecruitmentAdd : System.Web.UI.Page
    {
        FrameHelper frameHelper;

        protected void Page_Load(object sender, EventArgs e)
        {
            frameHelper = new FrameHelper(this);

            if (!IsPostBack)
            {
                InitializeContent();
            }
            else
            {
                Save();
            }
        }

        private void Save()
        {
            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                RecruitmentInfo recrDb = new RecruitmentInfo();

                recrDb.Title = tb_title.Text;
                recrDb.WorkPost = ddl_pos.SelectedValue;
                recrDb.WorkAddr = ddl_addr.SelectedValue;
                recrDb.ExpiryDate = DateTime.Parse(tb_expiry.Text);
                recrDb.RequstNum = int.Parse(tb_reqnum.Text);
                recrDb.ShowOrder = int.Parse(tb_order.Text);
                recrDb.Content = txt_xx.Value;
                recrDb.CreateDate = DateTime.Now;

                recrDb.Kind = (string)ViewState["kind"];

                session.Save(recrDb);
                session.Flush();
            }

            frameHelper.Alert(new ReturnCode()
            {
                statusCode = 200,
                message = "操作成功!",
                callbackType = "closeCurrent",
                navTabId = frameHelper.NavTabId
            });
        }

        private void InitializeContent()
        {
            //初始化控件值
            ParamKit.Bind("WorkPos", ddl_pos, null, new List<ListItem>() { ParamKit.ParamItemEx_QXZ() }, null, "-1", "-1");
            ParamKit.Bind("WorkCity", ddl_addr, null, new List<ListItem>() { ParamKit.ParamItemEx_QXZ() }, null, "-1", "-1");

            ViewState["kind"] = (String.IsNullOrEmpty(Request["Kind"]) ? "" : Request["Kind"]);
        }
    }
}
